//
//  room.cpp
//  宿舍管理系统
//
//  Created by 孟强定 on 2020/6/26.
//  Copyright © 2020 mqd. All rights reserved.
//

#include "list.hpp"
#include "Room.hpp"
#include "Student.hpp"

Room::Room(int n):num(n){
    students=new Student*[n];
    for(int i=0;i<n;i++) students[i]=nullptr;
}
Room::Room(int buildingId,int floor, int id, int n):num(n){
    students= new Student*[n];
    for(int i=0;i<n;i++) students[i]=nullptr;
    this->buildingId= buildingId;
    this->floorId= floor;
    this->roomId= id;
}

void Room::init(int buildingId, int floorId, int roomId){
    this->buildingId=buildingId;
    this->floorId=floorId;
    this->roomId=roomId;
}

void Room::autoDistribute(){
    for(int i=0;i<num;i++){
        students[i]= allStudents.next();
        if (!students[i]) break;
        //std::cout<<building<<std::endl;
        students[i]->setRoom(buildingId, floorId, roomId,i+1);
    }
}

bool Room::autoDistributeOne(Student* stu){
    for(int i=0;i<num;i++){
        if (students[i]==nullptr){
            students[i]=stu;
            stu->setRoom(buildingId,floorId, roomId, i+1);
            return 1;
        }
    }
    return 0;
}
bool Room::delOne(Student *stu){
    if (!stu) return 0;
    students[stu->getbedId()-1]=nullptr; //记得减一
    return stu->delRoom();
}
void Room::print(){
    for(int i=0;i<num;i++){
        printf("==========%d号床========== \n",i+1);
        if (!students[i]) printf("未分配\n");
        else students[i]->print();
    }
}
